package com.alibaba.datax.core.util;


import org.zz.gmhelper.SM4Util;

public class EncryptionSm4 {

    /**
     * sm4加密
     * @param value
     * @return String
     */
    public static String encryption(String value){
        byte[] b = null;
        try {
            b = SM4Util.encrypt_Cbc_Padding(ByteUtils.fromHexString("11e092c3c341aa9b1924e31418ab6c61"), ByteUtils.fromHexString("ad4ffac9e77e4529a1ce248e1bcbc0e7"),value.getBytes());
        } catch (Exception e) {
            e.printStackTrace();
        }

        String encrypValue = ByteUtils.toHexString(b);

        return encrypValue;
    }

    /**
     * sm4解密
     * @param value
     * @return String
     */
    public static String decrypt(String value){
        byte[] b = null;
        try {
            b = SM4Util.decrypt_Cbc_Padding(ByteUtils.fromHexString("11e092c3c341aa9b1924e31418ab6c61"), ByteUtils.fromHexString("ad4ffac9e77e4529a1ce248e1bcbc0e7"), ByteUtils.fromHexString(value));
        } catch (Exception e) {

        }
        String a = new String(b);
        return a;
    }

    /**
     * sm4加密
     * @param value
     * @return String
     */
    public static String encryptionGbk(String value){
        byte[] b = null;
        try {
            b = SM4Util.encrypt_Cbc_Padding(ByteUtils.fromHexString("11e092c3c341aa9b1924e31418ab6c61"), ByteUtils.fromHexString("ad4ffac9e77e4529a1ce248e1bcbc0e7"),value.getBytes("GBK"));
        } catch (Exception e) {
            e.printStackTrace();
        }

        String encrypValue = ByteUtils.toHexString(b);

        return encrypValue;
    }
}
